
package org.mybatis.generator;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

/**
 * https://mapperhelper.github.io/docs/3.usembg/ MyBatis 通用 Mapper
 *
 * https://juejin.im/entry/59ec414b51882561a05a3907 MyBatis Generator系列(一)----MyBatis Generator简介
 *
 * MyBatis Generator官网地址
 * http://www.mybatis.org/generator/index.html
 *
 * @author Chris
 * @version V1.0
 * @date 2019/05/13
 */
public class MybatisGenerator {

    public static void main(String[] args) {
        try {
            System.out.println("**************start generator***************");
            List<String> warnings = new ArrayList<>();
            File configFile = new File(MybatisGenerator.class.getResource("/config/generatorConfig.xml").getFile());
            // File configFile = new File(MybatisGenerator.class.getResource("/config/generatorConfig.bak.xml").getFile());
            // File configFile = new File(MybatisGenerator.class.getResource("/config/generatorConfigSample.xml").getFile());
            ConfigurationParser cp = new ConfigurationParser(warnings);

            Configuration config = cp.parseConfiguration(configFile);
            DefaultShellCallback callback = new DefaultShellCallback(true);
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
            myBatisGenerator.generate(null);
            warnings.forEach(System.out::println);
            System.out.println("*******************end generator*************");

            // List<Properties> tables = new ArrayList<>();
            // String[] tableNames = {"t_business_line", "t_release_task_docker", "t_release_unit_docker", "t_user"};
            // String[] domainNames = {"BusinessLine", "ReleaseTaskDocker", "ReleaseUnitDocker", "User"};
            //
            // for (int i = 0; i < tableNames.length; i++) {
            //     Properties properties = new Properties();
            //     properties.setProperty("table.name", tableNames[i]);
            //     properties.setProperty("domain.object.name", domainNames[i]);
            //     tables.add(properties);
            // }

            // File configFile = new File(MybatisGenerator.class.getResource("/config/generatorConfig.xml").getFile());
            // PropertyParser.parse("..", property)
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}